<?php

namespace App\Http\Requests\customer;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait OrderRuleRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'prefix' => 'required|max:6|alpha_num',
            'suffix' => 'required|max:6|alpha_num',
            'serial_number' => 'required|integer|in:4,5,6'
        ], [
            'prefix.required' => '请填写前缀',
            'suffix.required' => '请填写后缀',
            'serial_number.required' => '请选择流水位数',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
